package com.hornsun.repository;

import com.hornsun.domain.dbo.User;
import com.hornsun.domain.dbo.UserExample;
import com.hornsun.repository.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by 编译中... on 2018/1/5.
 */
@Repository
public class UserRepository {
    @Autowired
    private UserMapper userMapper;

    public long getCountByUsernameAndPassword(String username,String password){
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andNameEqualTo(username).andPasswordEqualTo(password);
        return userMapper.countByExample(userExample);
    }

    public void insertUser(User user){
        userMapper.insert(user);
    }

    public void updateUser(User user){
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andMobileEqualTo(user.getMobile());
        userMapper.updateByExample(user,userExample);
    }

    public void deleteUser(String userName){
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andNameLike(userName);
        userMapper.selectByExample(userExample);
    }


}
